package com.burstly.lib.conveniencelayer;

import android.app.Activity;
import android.support.v4.app.Fragment;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
import android.view.animation.Animation;
import android.view.animation.Animation.AnimationListener;
import com.burstly.lib.conveniencelayer.events.AdCacheEvent;
import com.burstly.lib.conveniencelayer.events.AdFailEvent;
import com.burstly.lib.conveniencelayer.events.AdHideEvent;
import com.burstly.lib.conveniencelayer.events.AdShowEvent;
import com.burstly.lib.ui.BurstlyView;
import com.burstly.lib.util.LoggerExt;
import java.util.Iterator;
import java.util.List;

public class BurstlyAnimatedBanner extends BurstlyBaseAd
  implements ICacheable
{
  private IAnimationListener mAnimationCallbacks;
  private BannerAnimationListener mAnimationListener = new BannerAnimationListener();
  private boolean mAutoCached;
  private Animation mInAnim;
  private Animation mOutAnim;
  private int mRefreshRate;
  private State mState;
  private int mThrottleTime;

  @Deprecated
  public BurstlyAnimatedBanner(Activity paramActivity, int paramInt, boolean paramBoolean)
  {
    super(paramActivity, BurstlyAdSize.UNKNOWN);
    BurstlyView localBurstlyView = (BurstlyView)paramActivity.findViewById(paramInt);
    if (localBurstlyView == null)
      throw new RuntimeException("Invalid view Id.  A view with this Id could not be found with the activity's current layout");
    setBurstlyView(localBurstlyView);
    init();
    this.mAutoCached = paramBoolean;
  }

  @Deprecated
  public BurstlyAnimatedBanner(Activity paramActivity, ViewGroup paramViewGroup, ViewGroup.LayoutParams paramLayoutParams, String paramString1, String paramString2, int paramInt, boolean paramBoolean)
  {
    super(paramActivity, BurstlyAdSize.UNKNOWN);
    initNewAnimatedBanner(paramActivity, paramViewGroup, paramLayoutParams, paramString1, paramString2);
    this.mRefreshRate = paramInt;
    this.mAutoCached = paramBoolean;
  }

  public BurstlyAnimatedBanner(Activity paramActivity, BurstlyAdSize paramBurstlyAdSize, int paramInt, boolean paramBoolean)
  {
    super(paramActivity, paramBurstlyAdSize);
    BurstlyView localBurstlyView = (BurstlyView)paramActivity.findViewById(paramInt);
    if (localBurstlyView == null)
      throw new RuntimeException("Invalid view Id.  A view with this Id could not be found with the activity's current layout");
    setBurstlyView(localBurstlyView);
    init();
    this.mAutoCached = paramBoolean;
  }

  public BurstlyAnimatedBanner(Activity paramActivity, BurstlyAdSize paramBurstlyAdSize, ViewGroup paramViewGroup, ViewGroup.LayoutParams paramLayoutParams, String paramString1, String paramString2, int paramInt, boolean paramBoolean)
  {
    super(paramActivity, paramBurstlyAdSize);
    initNewAnimatedBanner(paramActivity, paramViewGroup, paramLayoutParams, paramString1, paramString2);
    this.mRefreshRate = paramInt;
    this.mAutoCached = paramBoolean;
  }

  @Deprecated
  public BurstlyAnimatedBanner(Fragment paramFragment, int paramInt, boolean paramBoolean)
  {
    super(paramFragment, BurstlyAdSize.UNKNOWN);
    View localView = paramFragment.getView();
    if (localView == null)
      throw new RuntimeException("fragment.getView returned null. Has this fragment inflated a layout?");
    BurstlyView localBurstlyView = (BurstlyView)localView.findViewById(paramInt);
    if (localBurstlyView == null)
      throw new RuntimeException("Invalid view Id.  A view with this Id could not be found in the current layout");
    setBurstlyView(localBurstlyView);
    init();
    this.mAutoCached = paramBoolean;
  }

  @Deprecated
  public BurstlyAnimatedBanner(Fragment paramFragment, ViewGroup paramViewGroup, ViewGroup.LayoutParams paramLayoutParams, String paramString1, String paramString2, int paramInt, boolean paramBoolean)
  {
    super(paramFragment, BurstlyAdSize.UNKNOWN);
    initNewAnimatedBanner(paramFragment.getActivity(), paramViewGroup, paramLayoutParams, paramString1, paramString2);
    this.mRefreshRate = paramInt;
    this.mAutoCached = paramBoolean;
  }

  public BurstlyAnimatedBanner(Fragment paramFragment, BurstlyAdSize paramBurstlyAdSize, int paramInt, boolean paramBoolean)
  {
    super(paramFragment, paramBurstlyAdSize);
    View localView = paramFragment.getView();
    if (localView == null)
      throw new RuntimeException("fragment.getView returned null. Has this fragment inflated a layout?");
    BurstlyView localBurstlyView = (BurstlyView)localView.findViewById(paramInt);
    if (localBurstlyView == null)
      throw new RuntimeException("Invalid view Id.  A view with this Id could not be found in the current layout");
    setBurstlyView(localBurstlyView);
    init();
    this.mAutoCached = paramBoolean;
  }

  public BurstlyAnimatedBanner(Fragment paramFragment, BurstlyAdSize paramBurstlyAdSize, ViewGroup paramViewGroup, ViewGroup.LayoutParams paramLayoutParams, String paramString1, String paramString2, int paramInt, boolean paramBoolean)
  {
    super(paramFragment, paramBurstlyAdSize);
    initNewAnimatedBanner(paramFragment.getActivity(), paramViewGroup, paramLayoutParams, paramString1, paramString2);
    this.mRefreshRate = paramInt;
    this.mAutoCached = paramBoolean;
  }

  private void init()
  {
    this.mState = State.Offscreen;
    this.mThrottleTime = -1;
    this.mRefreshRate = getBurstlyView().getDefaultSessionLife();
  }

  private void initNewAnimatedBanner(Activity paramActivity, ViewGroup paramViewGroup, ViewGroup.LayoutParams paramLayoutParams, String paramString1, String paramString2)
  {
    BurstlyView localBurstlyView = new BurstlyView(paramActivity);
    localBurstlyView.setPublisherId(Burstly.getAppID());
    localBurstlyView.setZoneId(paramString1);
    localBurstlyView.setBurstlyViewId(paramString2);
    setBurstlyView(localBurstlyView);
    init();
    if (paramLayoutParams != null)
    {
      paramViewGroup.addView(localBurstlyView, paramLayoutParams);
      return;
    }
    paramViewGroup.addView(localBurstlyView);
  }

  public void cacheAd()
  {
    if (this.mAutoCached)
      throw new RuntimeException("Automatic caching enabled for " + getName() + ". Do not attempt to manually cache an ad also");
    super.baseCacheAd();
  }

  public int getRefreshRate()
  {
    BurstlyView localBurstlyView = getBurstlyView();
    if (localBurstlyView != null)
      return localBurstlyView.getDefaultSessionLife();
    sLog.logError("Burstly Convenience Layer", "Should create a BurstlyAnimatedBanner before calling this method.", new Object[0]);
    return 0;
  }

  public State getState()
  {
    return this.mState;
  }

  public boolean hasCachedAd()
  {
    return super.baseHasCachedAd();
  }

  public void hideAd()
  {
    throwIfNotOnMainThread();
    if (this.mState.ordinal() < State.ShowTriggered.ordinal())
    {
      sLog.logWarning("Burstly Convenience Layer", "Calling hide without calling show.", new Object[0]);
      return;
    }
    if (this.mState == State.ShowTriggered)
    {
      sLog.logError("Burstly Convenience Layer", "Hiding an ad immediately after trying to show it before it made it to the screen.  Impression will be tracked but not shown.", new Object[0]);
      this.mState = State.Offscreen;
      return;
    }
    if (this.mState == State.OutroAnim)
    {
      sLog.logWarning("Burstly Convenience Layer", "Calling hide multiple times", new Object[0]);
      return;
    }
    if (this.mState == State.IntroAnim)
      sLog.logWarning("Burstly Convenience Layer", "Calling hide before intro transition was finished", new Object[0]);
    getBurstlyView().resetDefaultSessionLife();
    if (this.mOutAnim == null)
    {
      this.mState = State.Offscreen;
      getBurstlyView().setVisibility(8);
      if (this.mAnimationCallbacks != null)
        this.mAnimationCallbacks.onOutroAnimEnd(this);
      onHide(new AdHideEvent(false, this.mLastShow));
      return;
    }
    this.mState = State.OutroAnim;
    getBurstlyView().startAnimation(this.mOutAnim);
  }

  public boolean isCachingAd()
  {
    return super.baseIsCachingAd();
  }

  public boolean isVisible()
  {
    return this.mState.ordinal() >= State.IntroAnim.ordinal();
  }

  protected void onCache(AdCacheEvent paramAdCacheEvent)
  {
    super.onCache(paramAdCacheEvent);
    if (this.mState == State.ShowTriggered)
      super.showAd();
    while (this.mState == State.Offscreen)
      return;
    LoggerExt localLoggerExt = sLog;
    Object[] arrayOfObject = new Object[1];
    arrayOfObject[0] = this.mState.toString();
    localLoggerExt.logError("Burstly Convenience Layer", "Unexpected state. Banner in state {0} when precache finished.", arrayOfObject);
  }

  protected void onFail(AdFailEvent paramAdFailEvent)
  {
    if (paramAdFailEvent.wasRequestThrottled());
    for (this.mThrottleTime = paramAdFailEvent.getMinTimeUntilNextRequest(); ; this.mThrottleTime = 0)
    {
      if (this.mState != State.OnScreen)
        this.mState = State.Offscreen;
      this.mCachingState = BurstlyBaseAd.CachingState.Idle;
      if ((this.mAutoCached) && (paramAdFailEvent.wasFailureResultOfCachingAttempt()))
        break;
      Iterator localIterator = this.mListeners.iterator();
      while (localIterator.hasNext())
        ((IBurstlyListener)localIterator.next()).onFail(this, paramAdFailEvent);
    }
  }

  protected void onHide(AdHideEvent paramAdHideEvent)
  {
    super.onHide(paramAdHideEvent);
    if ((this.mAutoCached) && (!paramAdHideEvent.isARefresh()) && (!paramAdHideEvent.getMatchingShowEvent().isActivityInterstitial()))
      super.baseCacheAd();
  }

  protected void onShow(AdShowEvent paramAdShowEvent)
  {
    if (this.mState == State.ShowTriggered)
    {
      super.onShow(paramAdShowEvent);
      getBurstlyView().setVisibility(0);
      if (this.mInAnim != null)
      {
        this.mState = State.IntroAnim;
        getBurstlyView().startAnimation(this.mInAnim);
      }
      do
      {
        return;
        this.mState = State.OnScreen;
      }
      while (this.mAnimationCallbacks == null);
      this.mAnimationCallbacks.onIntroAnimEnd(this);
      return;
    }
    if (this.mState == State.OnScreen)
    {
      super.onShow(paramAdShowEvent);
      return;
    }
    LoggerExt localLoggerExt = sLog;
    Object[] arrayOfObject = new Object[1];
    arrayOfObject[0] = this.mState.toString();
    localLoggerExt.logWarning("Burstly Convenience Layer", "Received onLoad callback when banner was in state {0}", arrayOfObject);
  }

  protected void resumed()
  {
    super.resumed();
    if ((this.mAutoCached) && (!hasCachedAd()))
      super.baseCacheAd();
  }

  public void setAnimatedBannerListener(IAnimationListener paramIAnimationListener)
  {
    this.mAnimationCallbacks = paramIAnimationListener;
  }

  public void setAnims(Animation paramAnimation1, Animation paramAnimation2)
  {
    if ((this.mState == State.IntroAnim) || (this.mState == State.OutroAnim))
      throw new RuntimeException("Attempting to change anims while currently animating");
    if (this.mInAnim != null)
      this.mInAnim.setAnimationListener(null);
    if (this.mOutAnim != null)
      this.mOutAnim.setAnimationListener(null);
    this.mInAnim = paramAnimation1;
    this.mOutAnim = paramAnimation2;
    if (this.mInAnim != null)
      this.mInAnim.setAnimationListener(this.mAnimationListener);
    if (this.mOutAnim != null)
      this.mOutAnim.setAnimationListener(this.mAnimationListener);
  }

  public void setRefreshRate(int paramInt)
  {
    BurstlyView localBurstlyView = getBurstlyView();
    if (localBurstlyView != null)
    {
      localBurstlyView.setDefaultSessionLife(paramInt);
      return;
    }
    sLog.logError("Burstly Convenience Layer", "Should create a BurstlyAnimatedBanner before calling this method.", new Object[0]);
  }

  public void showAd()
  {
    throwIfNotOnMainThread();
    if (this.mState.ordinal() >= State.IntroAnim.ordinal())
      super.showAd();
    do
    {
      return;
      if (this.mState == State.ShowTriggered)
      {
        sLog.logWarning("Burstly Convenience Layer", "Trying to show an ad when show has already been called", new Object[0]);
        return;
      }
      if (this.mCachingState != BurstlyBaseAd.CachingState.Idle)
      {
        sLog.logWarning("Burstly Convenience Layer", "calling", new Object[0]);
        boolean bool = hasCachedAd();
        sLog.logWarning("Burstly Convenience Layer", "completed", new Object[0]);
        if (bool)
        {
          this.mState = State.ShowTriggered;
          if (this.mRefreshRate > 0)
            getBurstlyView().setDefaultSessionLife(this.mRefreshRate);
          super.showAd();
          return;
        }
        if (this.mCachingState == BurstlyBaseAd.CachingState.Retrieving)
        {
          this.mState = State.ShowTriggered;
          sLog.logWarning("Burstly Convenience Layer", "Attempting to show banner before it finished precaching", new Object[0]);
          return;
        }
        sLog.logError("Burstly Convenience Layer", "Attempting to show precached banner while in idle state", new Object[0]);
        return;
      }
      this.mThrottleTime = 0;
      if (this.mRefreshRate > 0)
        getBurstlyView().setDefaultSessionLife(this.mRefreshRate);
      super.showAd();
    }
    while (this.mThrottleTime != 0);
    this.mState = State.ShowTriggered;
  }

  protected class BannerAnimationListener
    implements Animation.AnimationListener
  {
    protected BannerAnimationListener()
    {
    }

    public void onAnimationEnd(Animation paramAnimation)
    {
      if (paramAnimation == BurstlyAnimatedBanner.this.mInAnim)
      {
        if (BurstlyAnimatedBanner.this.mState != BurstlyAnimatedBanner.State.IntroAnim)
          BurstlyBaseAd.sLog.logWarning("Burstly Convenience Layer", "Intro anim finished but no longer in intro anim state", new Object[0]);
        BurstlyAnimatedBanner.access$102(BurstlyAnimatedBanner.this, BurstlyAnimatedBanner.State.OnScreen);
        if (BurstlyAnimatedBanner.this.mAnimationCallbacks != null)
          BurstlyAnimatedBanner.this.mAnimationCallbacks.onIntroAnimEnd(BurstlyAnimatedBanner.this);
        return;
      }
      if (BurstlyAnimatedBanner.this.mState != BurstlyAnimatedBanner.State.OutroAnim)
        BurstlyBaseAd.sLog.logWarning("Burstly Convenience Layer", "Outro anim finished but no longer in outro anim state", new Object[0]);
      BurstlyAnimatedBanner.access$102(BurstlyAnimatedBanner.this, BurstlyAnimatedBanner.State.Offscreen);
      BurstlyAnimatedBanner.this.getBurstlyView().setVisibility(8);
      if (BurstlyAnimatedBanner.this.mAnimationCallbacks != null)
        BurstlyAnimatedBanner.this.mAnimationCallbacks.onOutroAnimEnd(BurstlyAnimatedBanner.this);
      BurstlyAnimatedBanner.this.onHide(new AdHideEvent(false, BurstlyAnimatedBanner.this.mLastShow));
    }

    public void onAnimationRepeat(Animation paramAnimation)
    {
    }

    public void onAnimationStart(Animation paramAnimation)
    {
    }
  }

  public static abstract interface IAnimationListener
  {
    public abstract void onIntroAnimEnd(BurstlyAnimatedBanner paramBurstlyAnimatedBanner);

    public abstract void onOutroAnimEnd(BurstlyAnimatedBanner paramBurstlyAnimatedBanner);
  }

  public static enum State
  {
    static
    {
      IntroAnim = new State("IntroAnim", 2);
      OnScreen = new State("OnScreen", 3);
      OutroAnim = new State("OutroAnim", 4);
      State[] arrayOfState = new State[5];
      arrayOfState[0] = Offscreen;
      arrayOfState[1] = ShowTriggered;
      arrayOfState[2] = IntroAnim;
      arrayOfState[3] = OnScreen;
      arrayOfState[4] = OutroAnim;
    }
  }
}

/* Location:           E:\android\Toy Defense 2_dex2jar.jar
 * Qualified Name:     com.burstly.lib.conveniencelayer.BurstlyAnimatedBanner
 * JD-Core Version:    0.6.2
 */